<div class="model_actions_toolbar">
    <?php $this->widget('backend.components.ModelActions'); ?>
</div>

<style type="text/css">
    .album { margin: 0 0 20px; }
    .album .title {
        margin-top: 20px;
        font-size: 1.5em; font-weight: bold; border-bottom: 1px solid #C9E0ED;
    }
    .album .album_infos {
        width: 100%; height: 66px;
        color: #888; margin: 0 0 5px;
    }
    .album_infos div.cover {
        width: 60px; height: 66px; float: left;
        background: url(<?php echo YHtml::mediaUrl("images/bg_cover.gif", true); ?>);
    }
    .album_infos div.cover img {
        width: 54px; height: 54px;
        margin: 9px 3px 3px 3px;
    }
    .album_summary {
        -moz-border-radius:7px;
        padding: 10px;
        background: #F5F5F5;
        margin: 5px 0;
    }
    .album div.pictures_box {
        -moz-border-radius: 7px;
        height: auto;
        padding: 5px;
        background: #EFFDFF;
    }
    ul.album_pictures { padding: 0; margin: 0; }
    ul.album_pictures li {
        width: 120px; height: 160px; padding: 6px; _padding: 6px; float: left;
        background: url(<?php echo YHtml::mediaUrl('images/bg_picture.gif', true) ?>) no-repeat top 50%;
    }
    ul.album_pictures li img { width: 80px; height: 80px; padding: 0px 0 0 20px;}
    ul.album_pictures li img.btn { width: 16px; height: 16px; padding: 0; margin: 0; }
    ul.album_pictures li span { padding-right: 10px; }
    ul.album_pictures li h4.icons { padding-top: 10px; text-align: center; }
    ul.album_pictures li h4.name{ padding-top: 5px; text-align: left; }
    ul.album_pictures li h4.num{ padding-top: 5px; text-align: left; }
    ul.album_pictures li h4.num span { padding: 0 4px; background-color: #000; color: #fff; }
</style>


<div class="album">
    <div class="title">
        <?php echo CHtml::encode($album->name); ?>
    </div>
    <div class="album_infos">
        <div class="cover" id="album_cover">
            <?php echo CHtml::link(CHtml::image($album->coverPicture, $album->name), array('node' => $album->node_id, 'id' => $album->id)); ?>
        </div>
        <div style="float: left; padding-left: 20px;">
            <p>Posted at <?php echo date('Y-m-d H:m:s', $album->created); ?></p>
            <p>Total: <?php echo $album->pictures_count; ?> pictures.</p>
        </div>
    </div>
    <div class="album_summary">
        <?php
        $this->beginWidget('CMarkdown', array('purifyOutput' => true));
        echo $album->summary;
        $this->endWidget();
        ?>
    </div>
    <div class="pictures_box">
        <ul class="album_pictures clearfix">
            <?php foreach ($album->pictures as $pic): ?>
            <li id="pic_<?php echo $pic->id; ?>">
                <div class="pic">
                    <?php echo CHtml::link(CHtml::image($pic->thumbnailSource, $pic->name), array('view', 'id' => $pic->album_id, 'node' => Yii::app()->request->getParam('node'), 'pid' => $pic->id)); ?>
                </div>
                <h4 class="icons">
                    <?php
                    echo CHtml::ajaxLink(CHtml::image(YHtml::mediaUrl('images/btn_set_cover.png', true), 'set this picture a cover image', array('class' => 'btn')), array('albums/setCover', 'aid' => $album->id, 'pid' => $pic->id), array(
                        'type' => 'POST',
                        'url' => array('setCover'),
                        'update' => '#album_cover',
                        'complete' => 'function() { $("#album_cover").html($("#pic_' . $pic->id . ' > div > a").html()); }',
                    ));
                    ?>
                    <span></span>
                    <?php
                    echo CHtml::ajaxLink(CHtml::image(YHtml::mediaUrl('images/btn_remove_picture.png', true), 'remove this picture', array('class' => 'btn')), array('albums/removePicture', 'pid' => $pic->id), array(
                        'type' => 'POST',
                        'url' => array('removePicture'),
                        'beforeSend' => 'function() { return confirm(\''. Yii::t('jsmsg', 'are_you_want_to_delete_this_picture', array('name' => CHtml::encode($pic->name))) . '\'); }',
                        'complete' => 'function() { $("#pic_' . $pic->id . '").addClass("hide"); }',
                    ));
                    ?>
                </h4>
                <h4 class="name">
                    <?php echo CHtml::encode($pic->name); ?>
                </h4>
                <h4 class="num">
                    <span><?php echo $pic->order_pos; ?></span>
                    <span><?php echo $pic->clicks_count; ?> Clicks</span>
                </h4>
            </li>
            <?php endforeach; ?>
        </ul>
    </div>
</div>

<div style="width: 100%; clear: both; padding: 10px 0;">
    <?php
    echo CHtml::beginForm(array('view',
        'id' => Yii::app()->request->getParam('id'),
        'node' => Yii::app()->request->getParam('node')),
        'post'
    );
    echo CHtml::submitButton(Yii::t('album', 'add_picture'), array('class' => 'btn'));
    echo CHtml::endForm();
    ?>
</div>

<div class="commend" style="clear: both;">
    <?php if (Yii::app()->user->hasFlash('add_picture_success')): ?>
    <div class="success">
        <?php echo Yii::app()->user->getFlash('add_picture_success'); ?>
    </div>
    <?php elseif (Yii::app()->user->hasFlash('update_picture_success')): ?>
    <div class="success">
        <?php echo Yii::app()->user->getFlash('update_picture_success'); ?>
    </div>
    <?php endif; ?>
    <?php
    $this->renderPartial('/albums/_picture',array(
        'picture' => $picture
    ));
    ?>
</div>